<template>
  <div class="gongjutop">
    <div class="kflexc" style=" margin: 20px;" v-if="gengxinshujuing == 0">
      <el-button type="primary"  @click="gengxin()" round :loading="gengxining">更新数据</el-button>
      <div style="margin-left: 20px; font-size: 14px; color: #999;">当前统计数据更新时间：{{gengxintime}}</div>
    </div>
    <div class="kflexc" style=" margin: 20px; " v-if="gengxinshujuing == 1">
      <div>数据待更新...</div>
      <div style="color:#999; margin-left: 20px; font-size: 14px;">将于{{natian}} 02:00:00 开始更新，请更新完成后查看</div>
    </div>
    <div class="powertop">
      <router-link class="powertopli" to="/lirun/shijianchaxun/wode">按照时间罗列</router-link>
      <router-link class="powertopli" to="/lirun/yongjinbaobiao" v-if="shopid == 50481 || shopid == 304676">商品佣金报表</router-link>
      <router-link class="powertopli" to="/lirun/lirunbaobiao">销售渠道利润报表</router-link>
      <router-link class="powertopli" to="/lirun/xiazai">表单下载</router-link>
    </div>
  </div>
</template>

<script>
  import axios from 'axios'
  import moment from 'moment';
  export default {
    name: "lirun_nav",
    data() {
      return {
        shopid:'',
        gengxining:false,
        gengxintime:"",
        gengxinshujuing:2,
        natian:moment().add('day',1).format('YYYY-MM-DD'),
      }
    },
    created() {
			this.shopid = JSON.parse(localStorage.getItem('SHOP')).shop_id;
      this.getgengxin()
    },
    mounted() {

    },
    methods: {
      getgengxin:function(){
        axios.get('/api/plan-market/income/income/status')
          .then(response => {
            if (response.data.msg.code == 0) {
              this.gengxinshujuing = response.data.data.delayed_update
              this.gengxintime = response.data.data.last_update_time
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
      gengxin:function(){
        this.gengxining = true
        axios.post('/api/plan-market/income/income/delayed/update')
          .then(response => {
            if (response.data.msg.code == 0) {
              this.$message.success('操作成功');
              this.gengxining = false
              this.getgengxin()
            } else {
              this.$message.error(response.data.msg.info);
              this.gengxining = false
            }
          })
      },

    }
  }
</script>

<style lang="scss" scoped>
  .gongjutop {
    .powertop {
    	display: flex;
    	background:#f9f9f9;
    }
    .powertopli {
    	flex-basis: 180px;
    	line-height: 50px;
    	border-bottom: 3px #F9F9F9 solid;
    	color: #727272;
    	border-right: 1px #F9F9F9 solid;
    	font-size: 16px;
    	text-align: center;
    }
    .router-link-active {
    	background: #FFFFFF;
    	border-bottom: 3px #2974FF solid;
    }
  }
</style>
